﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using ReactReduxTool.Model;
using System.Windows.Forms;

namespace ReactReduxTool.Utils {

    public class ConfigUtil
    {

        private static List<ConfigItemInfoEntry> CONFIGS;

        private static ConfigUtil configUtil;

        public static ConfigUtil GetInstance() {
            configUtil = configUtil ?? new ConfigUtil();
            return configUtil;
        }

        private ConfigUtil()
        {
            string content = File.OpenText(Application.StartupPath + "/../../assets/configs/PkgConf.ini").ReadToEnd();
            DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(List<ConfigItemInfoEntry>));
            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(content.Replace(@"\r","").Replace(@"\n","").Replace(@"\t",""))))
            {
                CONFIGS = (List<ConfigItemInfoEntry>) jsonSerializer.ReadObject(stream);
            }
        }

        public List<ConfigItemInfoEntry> GetConfigs() {
            return CONFIGS;
        }

    }

}
